﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Org.BouncyCastle.Ocsp;

namespace TeachingAffairsManagementSystem
{
    public partial class Main : System.Web.UI.Page
    {
        private Control _leftNavbar = new Control();
        private Control _rightContent = new Control();

        protected void Page_Load(object sender, EventArgs e)
        {
            // 判断登录状态
            if ((bool) Session["isLoggedIn"] == false)
            {
                // 未登录 跳回主页
                Response.Redirect("~/Home.aspx");
            }
            else
            {
                // 已登录
                // 判断用户类型 判断内容 动态加载控件
                switch (Session["userType"])
                {
                    case "student":
                        _leftNavbar = LoadControl("~/UserControl/LeftNavbar/StudentLeftNavbar.ascx");
                        switch (Request.QueryString["p"])
                        {
                            case "ml":
                                Title = "我的课程";
                                _rightContent = LoadControl("~/UserControl/RightContent/Student/MyLesson.ascx");
                                break;
                            case "lm":
                                Title = "课程市场";
                                _rightContent = LoadControl("~/UserControl/RightContent/Student/LessonMarket.ascx");
                                break;
                            case "info":
                                Title = "我的信息";
                                _rightContent = LoadControl("~/UserControl/RightContent/Student/Info.ascx");
                                break;
                            default:
                                Response.Redirect("~/Main.aspx?p=ml");
                                break;
                        }

                        break;
                    case "teacher":
                        _leftNavbar = LoadControl("~/UserControl/LeftNavbar/TeacherLeftNavbar.ascx");
                        switch (Request.QueryString["p"])
                        {
                            case "ml":
                                Title = "我的课程";
                                _rightContent = LoadControl("~/UserControl/RightContent/Teacher/MyLesson.ascx");
                                break;
                            case "ms":
                                Title = "我的学生";
                                _rightContent = LoadControl("~/UserControl/RightContent/Teacher/MyStudent.ascx");
                                break;
                            case "info":
                                Title = "我的信息";
                                _rightContent = LoadControl("~/UserControl/RightContent/Teacher/Info.ascx");
                                break;
                            default:
                                Response.Redirect("~/Main.aspx?p=ml");
                                break;
                        }

                        break;
                    case "admin":
                        _leftNavbar = LoadControl("~/UserControl/LeftNavbar/AdminLeftNavbar.ascx");
                        switch (Request.QueryString["p"])
                        {
                            case "sm":
                                Title = "学生管理";
                                _rightContent = LoadControl("~/UserControl/RightContent/Admin/StudentManagement.ascx");
                                break;
                            case "tm":
                                Title = "教师管理";
                                _rightContent = LoadControl("~/UserControl/RightContent/Admin/TeacherManagement.ascx");
                                break;
                            case "lm":
                                Title = "课程管理";
                                _rightContent = LoadControl("~/UserControl/RightContent/Admin/LessonManagement.ascx");
                                break;
                            case "lsm":
                                Title = "选课管理";
                                _rightContent =
                                    LoadControl("~/UserControl/RightContent/Admin/LessonSelectionManagement.ascx");
                                break;
                            default:
                                Response.Redirect("~/Main.aspx?p=sm");
                                break;
                        }

                        break;
                }

                // 将控件添加到页面
                PHLeftNavbar.Controls.Add(_leftNavbar);
                PHRightContent.Controls.Add(_rightContent);
            }
        }
    }
}